package com.user_service.bean;

import jakarta.persistence.*;
import lombok.Data;
import com.user_service.util.SnowflakeIdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.time.LocalDateTime;

@Data
@Entity
@Table(name = "users")
public class User {
    @Id
    private Long id;

    @Column(unique = true)
    private String username;

    private String password;

    private String email;

    @Column(name  = "created_at")
    private LocalDateTime createdAt=LocalDateTime.now();
    
    @PrePersist
    public void prePersist() {
        if (this.id == null) {
            // 使用Snowflake算法生成ID
            // 注意：在实际生产环境中，应该通过依赖注入获取对应的ID生成器
            SnowflakeIdGenerator idGenerator = new SnowflakeIdGenerator(1);
            this.id = idGenerator.nextId();
        }
    }
}